package com.igeekhome.controller.api;


import com.igeekhome.util.ResultBean;
import com.igeekhome.util.sms.SendCode;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author 立以宁
 */

@RestController
@RequestMapping("/api/verify")
public class CodeVerifyController {

    @RequestMapping("/getCode")
    public ResultBean getCode(String phone) throws Exception {

        System.out.println("获取手机号码");
            Boolean result = SendCode.sendCode(phone);

            if (result) {
                return ResultBean.ok();
            } else {
                return ResultBean.fail("发送失败");
            }


    }

    @RequestMapping("/reg")
    public void register(String code,HttpSession session){

        System.out.println(code);
        System.out.println(session.getAttribute("code"));
        String sessionCode= (String) session.getAttribute("code");
        if (sessionCode==null || !(code.equals(sessionCode))){
            // return "验证码不正确";
        }else {
            //把用户数据存到数据库
        }
    }

}
